package com.qianbao.qianbaobusiness.ui.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qianbao.qianbaobusiness.R;

public class SignContractDialog extends Dialog {

    public static final int SIGN_PROCESS_STATE = 0;
    public static final int SIGN_FAIL_STATE    = 1;
    private int       mCurrentState;
    private View      mView;
    private ImageView mIvState;
    private TextView  mTvState;
    private TextView  mTvNotify;

    public SignContractDialog(@NonNull Context context) {
        this(context, R.style.customDialogTheme);
    }

    public SignContractDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    private void initView() {
        setCanceledOnTouchOutside(false);
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.dialog_sign_contract, null);
        addContentView(mView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        mIvState = mView.findViewById(R.id.iv_state);
        mTvState = mView.findViewById(R.id.tv_state);
        mTvNotify = mView.findViewById(R.id.tv_notify);
    }

    public void setState(int state) {
        mCurrentState = state;
        switch (state) {
            case SIGN_PROCESS_STATE:
                setCanceledOnTouchOutside(false);
                mTvState.setText("正在签约中，请稍等");
                mIvState.setImageResource(R.drawable.icon_transaction_detail_processing);
                mTvNotify.setVisibility(View.GONE);
                break;
            case SIGN_FAIL_STATE:
                setCanceledOnTouchOutside(true);
                mTvState.setText("签约失败，请重新签约");
                mIvState.setImageResource(R.drawable.icon_transaction_detail_fail);
                mTvNotify.setVisibility(View.GONE);
                break;
            default:
                break;
        }
    }

    public int getState() {
        return mCurrentState;
    }

    @Override
    public void onBackPressed() {
        if (mCurrentState == SIGN_PROCESS_STATE) {
            return;
        } else {
            super.onBackPressed();
        }
    }
}

